package com.explorati.LeetCode404.isLeftNode;

/**
 * 404. Sum of Left Leaves  计算节点值 不符合题意，题意是计算左节点的值的和
 * 
 * @author explorati
 *
 */
public class Solution {
	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}

	public int sumOfLeftLeaves(TreeNode root) {
		if (root == null) {
			return 0;
		}
		int num = 0;
		return CountLeftNode(root, num);
	}

	public static int CountLeftNode(TreeNode node, int num) {
		if (node == null) {
			return num;
		} else if (node.left != null && node.right != null) {
			return CountLeftNode(node.left, num + 1) + CountLeftNode(node.right, num);
		} else if (node.left == null && node.right != null) {
			return CountLeftNode(node.right, num);
		} else if (node.left != null && node.right == null) {
			return CountLeftNode(node.left, num + 1);
		} else {
			return num;
		}
		// if (node.left == null && node.right == null) {
		// return num;
		// }
		// else if (node.left != null && node.right != null) {
		// return CountLeftNode(node.right, num) + CountLeftNode(node.left, num
		// + 1);
		// }
		// else if(node.left == null && node.right != null){
		// return
		// }

	}
}
